package com.aitou.mrylive.domain;

import com.google.gson.Gson;
import com.aitou.mrylive.data.bean.BaseResponse;
import com.aitou.mrylive.data.bean.LoginInfo;
import com.aitou.mrylive.data.repository.SourceFactory;

import java.util.HashMap;

import rx.Observable;

/**
 * @author Muyangmin
 * @since 1.0.0
 */
public class LoginManager {

    public Observable<BaseResponse<LoginInfo>> register(String username, String password){
        return SourceFactory.create().register(username, password);
    }

    public Observable<BaseResponse<LoginInfo>> autoLogin(String token){
        return SourceFactory.create().autoLogin(token);
    }

    public Observable<BaseResponse<LoginInfo>> login(String username, String password){
        return SourceFactory.create().login(username, password);
    }

    public Observable<BaseResponse<LoginInfo>> loginByCaptcha(String username, String captcha){
        return SourceFactory.create().loginByCaptcha(username, captcha);
    }

    public Observable<BaseResponse<LoginInfo>> thirdLogin(String openId, String platform,
                                                          HashMap<String, Object> map){
        Gson gson = new Gson();
        String result = gson.toJson(map);
        return SourceFactory.create().thirdLogin(openId, platform, result);
    }

    public Observable<BaseResponse<String>> sendCaptcha(String phone){
        return SourceFactory.create().sendCaptcha(phone);
    }
}
